<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>loaclStorage</title>
</head>
<body>
    <h2>sessionStorage</h2>
    <button onclick="saveData()">点击保存数据信息</button>
    <button onclick="readData()">点击读取数据信息</button>
    <button onclick="deleteData()">点击删除数据信息</button>
    <button onclick="deleteAllData()">点击清除所有数据信息</button>

    <script type="text/javascript">
        let p = {name:"邓伦",age:29}

        function saveData(){
            sessionStorage.setItem('msg','hello')
            sessionStorage.setItem('msg2',666)
            sessionStorage.setItem('person',JSON.stringify(p))
        }
        function readData(){
            console.log(sessionStorage.getItem('msg'))
            console.log(sessionStorage.getItem('msg2'))

            const result = sessionStorage.getItem('person')
            console.log(JSON.parse(result))
        }
        function deleteData() {
            sessionStorage.removeItem('msg2')
        }

        function deleteAllData(){
            sessionStorage.clear()
        }
    </script>
</body>
</html>